<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>custom-tree</title>
  <script src="./js/vue.js"></script>
  <script src="./js/custom-tree.js"></script>
  <script src="./js/tree.js"></script>
  <link rel="stylesheet" href="./index.css">
  <style>
    .node {
      height: 40px;
      line-height: 40px;
      background: #f2f2f2;
      border-bottom: 1px solid #ffffff;
    }
  </style>
</head>

<body>
  <div id="app">
    <custom-tree :data="data1">
      <template v-slot:default="{ node, data }">
        <div class="node" :style="{
                  paddingLeft: node.level * 27 + 'px',
                  backgroundColor: 'rgb(212,235,' + 80 * node.level + ')'
                }"
                @click="clickNode(node)"
                >
          <span><input type="radio"></span>
          {{ node.name }}
        </div>
      </template>
    </custom-tree>
    <tree :data="data2">

    </tree>
  </div>
  <script>
    new Vue({
      el: "#app",
      data() {
        return {
          data1: [
            {
              id: 0,
              name: "New Collection",
              isOpen: true,
              type: "dir",
              children: [
                {
                  id: 3,
                  name: "New Request"
                },
                {
                  id: 1,
                  name: "New Collection",
                  isOpen: true,
                  type: "dir",
                  children: [
                    {
                      id: 2,
                      name: "New Request"
                    }
                  ]
                }
              ]
            },
            {
              id: 5,
              name: "New Request"
            }
          ],
          data2: null
        };
      },
      created() {
        this.data2 = JSON.parse(JSON.stringify(this.data1))
      },
      methods: {
        clickNode(node) {
          node.isOpen = !node.isOpen;
          console.log('custom - tree', node);
        }
      },
    });
  </script>
</body>

</html>